package product

import (
	"gitee.com/tang_q/gin-vue3-admin-api/global"
	"gorm.io/gorm"
)

type Region struct {
	gorm.Model
	Name string `gorm:"type:varchar(255);comment:区域名称;unique;not null" json:"name"`
}

func init() {
	err := global.DB.AutoMigrate(&Region{})
	if err != nil {
		global.Logger.Error("迁移Region失败", err)
		return
	}
}

func GetBrandRegions() (regions []string, err error) {
	err = global.DB.Model(&Region{}).Select("name").Find(&regions).Error
	return
}

func (r *Region) GetRegionByName(name string) error {
	return global.DB.Where("name = ?", name).First(r).Error
}
